import type { StorybookConfig } from "@storybook/react-webpack5";
const path = require("path");
const TsconfigPathsPlugin = require("tsconfig-paths-webpack-plugin");

const config: StorybookConfig = {
    stories: ["../src/**/*.mdx", "../src/**/*.stories.@(js|jsx|mjs|ts|tsx)"],
    addons: [
        "@storybook/addon-links",
        "@storybook/addon-essentials",
        {
            name: "@storybook/preset-create-react-app",
            options: {
                craOverrides: {
                    fileLoaderExcludes: ["less"],
                },
            },
        },
    ],
    framework: {
        name: "@storybook/react-webpack5",
        options: {
            builder: {
                useSWC: true,
            },
        },
    },
    docs: {
        autodocs: "tag",
    },
    staticDirs: ["../public"],
    webpackFinal: async (webpackConfig: any, { configType }) => {
        webpackConfig.module.rules.push({
            test: /\.less$/,
            use: [
                "style-loader",
                "css-loader",
                {
                    loader: "less-loader",
                    options: {
                        lessOptions: {
                            javascriptEnabled: true,
                        },
                    },
                },
            ],
            include: [
                path.resolve(__dirname, "../"),
                /[\\/]node_modules[\\/].*antd/,
            ],
        });
        return webpackConfig;
    },
};
export default config;
